import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  // 重定向：运行项目时，立即定位到首页，而不是 /
  {
    path: '/',
    redirect: '/home'
  }, {
    path: '/home',
    component: () => import('@/views/Home'),
    meta: {
      showFooter: true
    }
  }, {
    name: 'search',
    path: '/search/:keyword?',
    component: () => import('@/views/Search'),
    meta: {
      showFooter: true
    }
  }, {
    name: 'detail',
    path: '/detail/:skuId',
    component: () => import('@/views/Detail'),
    meta: {
      showFooter: true
    }
  }, {
    path: '/login',
    component: () => import('@/views/Login'),
    meta: {
      showFooter: false
    }
  }, {
    path: '/register',
    component: () => import('@/views/Register'),
    meta: {
      showFooter: false
    }
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
  // 滚动行为
  scrollBehavior(to, from, savedPosition) {
    // 始终滚动到顶部
    return { top: 0 }
  }
})

export default router
